package com.gitee.feizns.web.utils;

import java.util.List;
import java.util.function.Predicate;

/**
 * @author feizns
 * @since 2019/10/18
 */
public abstract class ListUtils {

    /**
     * 查找
     * @param list
     * @param test
     * @param <T>
     * @return
     */
    public static <T> int indexOf(List<T> list, Predicate<T> test) {
        if ( list != null ) {
            for (int i = 0; i < list.size(); i++) {
                if ( test.test(list.get(i)) )
                    return i;
            }
        }
        return -1;
    }

    /**
     * 包含
     * @param list
     * @param test
     * @param <T>
     * @return
     */
    public static <T> boolean include(List<T> list, Predicate<T> test) {
        return indexOf(list, test) != -1;
    }

}
